package com.orange.score.activity.more;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.orange.score.activity.common.CommonFootballActivity;
import com.orange.score.model.match.MatchManager;
import com.orange.score.network.ResultCodeType;
import com.orange.score.service.WeeklyMatchService;
import com.orange.score.service.WeeklyMatchServiceCallBack;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

public class WeeklyScheduleActivity extends CommonFootballActivity
  implements WeeklyMatchServiceCallBack
{
  public static final String TAG = "WeeklyScheduleActivity";
  private WeeklyScheduleAdapter adapter;
  private Button afterDateButton;
  private Button beforeDateButton;
  private TimeZone china;
  private Button dateButton;
  private String[] dates;
  private String[] dayofWeek;
  private ListView listView = null;
  private MatchManager matchManager;
  private int pageSize;
  private Date selectDate;
  private String selectDateString;
  private TextView textView;
  private WeeklyMatchService weeklyMatchService;

  public WeeklyScheduleActivity()
  {
    this.dates = new String[7];
    String[] arrayOfString = new String[7];
    arrayOfString[0] = "日";
    arrayOfString[1] = "一";
    arrayOfString[2] = "二";
    arrayOfString[3] = "三";
    arrayOfString[4] = "四";
    arrayOfString[5] = "五";
    arrayOfString[6] = "六";
    this.dayofWeek = arrayOfString;
    this.pageSize = 20;
    this.china = TimeZone.getTimeZone("GMT+08:00");
  }

  private Date addOneDay(String paramString)
  {
    Date localDate1;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    try
    {
      Date localDate2 = localSimpleDateFormat.parse(paramString);
      Calendar localCalendar = Calendar.getInstance();
      localCalendar.setTime(localDate2);
      localCalendar.add(5, 1);
      Date localDate3 = localCalendar.getTime();
      localDate1 = localDate3;
      return localDate1;
    }
    catch (ParseException localParseException)
    {
      Log.e("WeeklyScheduleActivity", localParseException.toString());
      localDate1 = null;
    }
  }

  private WeeklyMatchService getweeklyMatchService()
  {
    return new WeeklyMatchService();
  }

  private void initButton()
  {
    this.dateButton = ((Button)findViewById(2131558480));
    this.beforeDateButton = ((Button)findViewById(2131558483));
    this.afterDateButton = ((Button)findViewById(2131558484));
    this.dateButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        WeeklyScheduleActivity.access$0(this.this$0);
      }
    });
    this.beforeDateButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        WeeklyScheduleActivity.access$1(this.this$0);
      }
    });
    this.afterDateButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        WeeklyScheduleActivity.access$2(this.this$0);
      }
    });
  }

  private void initCalendar()
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTimeZone(this.china);
    this.dates[0] = new SimpleDateFormat("yyyy-MM-dd").format(localCalendar.getTime());
    int i = 1;
    while (true)
    {
      if (i >= 7)
      {
        this.selectDateString = this.dates[0];
        this.selectDate = parseString2Date(this.selectDateString);
        updateTextView();
        Log.i("WeeklyScheduleActivity", "curentDate=" + this.selectDateString);
        return;
      }
      localCalendar.add(5, 1);
      this.dates[i] = new SimpleDateFormat("yyyy-MM-dd").format(localCalendar.getTime());
      ++i;
    }
  }

  private void initListView()
  {
    this.listView = ((ListView)findViewById(2131558485));
    this.listView.setFastScrollEnabled(true);
    initializeAdapter();
    this.listView.setAdapter(this.adapter);
    this.listView.setOnScrollListener(new AbsListView.OnScrollListener(this)
    {
      public void onScroll(, int paramInt1, int paramInt2, int paramInt3)
      {
        WeeklyScheduleActivity.access$3(this.this$0).onScroll(paramInt1, paramInt2);
      }

      public void onScrollStateChanged(, int paramInt)
      {
      }
    });
  }

  private void initServicesAndManagers()
  {
    this.weeklyMatchService = getweeklyMatchService();
    this.matchManager = this.weeklyMatchService.getMatchManager();
  }

  private void initializeAdapter()
  {
    this.adapter = new WeeklyScheduleAdapter(this.matchManager.getUnfinishedMatch(), this);
    this.adapter.setPageSize(this.pageSize);
  }

  private void loadAllMatch()
  {
    this.weeklyMatchService.loadWeeklyMatch(this, this, this.selectDateString);
  }

  private Date minusOneDay(String paramString)
  {
    Date localDate1;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    try
    {
      Date localDate2 = localSimpleDateFormat.parse(paramString);
      Calendar localCalendar = Calendar.getInstance();
      localCalendar.setTime(localDate2);
      localCalendar.add(5, -1);
      Date localDate3 = localCalendar.getTime();
      localDate1 = localDate3;
      return localDate1;
    }
    catch (ParseException localParseException)
    {
      Log.e("WeeklyScheduleActivity", localParseException.toString());
      localDate1 = null;
    }
  }

  private String parseDate2String(Date paramDate)
  {
    return new SimpleDateFormat("yyyy-MM-dd").format(paramDate);
  }

  private Date parseString2Date(String paramString)
  {
    Date localDate1;
    Date localDate2;
    try
    {
      localDate2 = new SimpleDateFormat("yyyy-MM-dd").parse(paramString);
      localDate1 = localDate2;
      return localDate1;
    }
    catch (ParseException localParseException)
    {
      Log.e("WeeklyScheduleActivity", localParseException.toString());
      localDate1 = null;
    }
  }

  private void setDate()
  {
    5 local5 = new DialogInterface.OnClickListener(this)
    {
      public void onClick(, int paramInt)
      {
        paramDialogInterface.dismiss();
        WeeklyScheduleActivity.access$5(this.this$0, WeeklyScheduleActivity.access$4(this.this$0)[paramInt]);
        WeeklyScheduleActivity.access$8(this.this$0, WeeklyScheduleActivity.access$7(this.this$0, WeeklyScheduleActivity.access$6(this.this$0)));
        WeeklyScheduleActivity.access$9(this.this$0);
        Log.i("WeeklyScheduleActivity", "click " + WeeklyScheduleActivity.access$6(this.this$0));
        WeeklyScheduleActivity.access$10(this.this$0);
      }
    };
    new AlertDialog.Builder(this).setTitle("选择日期").setSingleChoiceItems(this.dates, -1, local5).setNegativeButton(2131361823, new DialogInterface.OnClickListener(this)
    {
      public void onClick(, int paramInt)
      {
        Log.d("WeeklyScheduleActivity", "click cancel");
      }
    }).create().show();
  }

  private void updateAfterMatch()
  {
    if (validateDate() > 0)
      Toast.makeText(getApplicationContext(), "已经到达最后页，请往前翻", 1).show();
    while (true)
    {
      return;
      this.selectDate = addOneDay(this.selectDateString);
      this.selectDateString = parseDate2String(this.selectDate);
      updateTextView();
      loadAllMatch();
    }
  }

  private void updateBeforeMatch()
  {
    if (validateDate() < 0)
      Toast.makeText(getApplicationContext(), "已经到达最前页，请往后翻", 1).show();
    while (true)
    {
      return;
      this.selectDate = minusOneDay(this.selectDateString);
      this.selectDateString = parseDate2String(this.selectDate);
      updateTextView();
      loadAllMatch();
    }
  }

  private void updateTextView()
  {
    Calendar.getInstance().setTime(this.selectDate);
    String str1 = this.dayofWeek[this.selectDate.getDay()];
    String str2 = this.selectDateString.concat(" ").concat("星期").concat(str1);
    this.textView.setText(str2);
  }

  private int validateDate()
  {
    int i;
    Calendar localCalendar1 = Calendar.getInstance();
    Calendar localCalendar2 = Calendar.getInstance();
    localCalendar2.add(5, 6);
    Date localDate1 = localCalendar1.getTime();
    Date localDate2 = localCalendar2.getTime();
    String str1 = parseDate2String(localDate1);
    String str2 = parseDate2String(localDate2);
    Log.i("WeeklyScheduleActivity", str1 + "," + str2 + "," + this.selectDateString);
    if (this.selectDateString.compareTo(str1) <= 0)
      i = -1;
    while (true)
    {
      while (true)
      {
        return i;
        if (this.selectDateString.compareTo(str2) < 0)
          break;
        i = 1;
      }
      i = 0;
    }
  }

  public void loadAllMatchFinish(ResultCodeType paramResultCodeType)
  {
    switch ($SWITCH_TABLE$com$orange$score$network$ResultCodeType()[paramResultCodeType.ordinal()])
    {
    default:
    case 1:
    }
    while (true)
    {
      return;
      new ArrayList();
      List localList = this.matchManager.getUnfinishedMatch();
      this.adapter.updateList(localList);
      Log.i("WeeklyScheduleActivity", "<loadAllMatchFinish> unfinshedMatchList.size=" + localList.size());
      this.adapter.notifyDataSetChanged();
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903078);
    this.textView = ((TextView)findViewById(2131558482));
    initCalendar();
    initButton();
    initServicesAndManagers();
    initListView();
    loadAllMatch();
  }

  public void onRefresh()
  {
    loadAllMatch();
  }
}